home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
prodpack.zip
/
DB4PPSRC.EXE
/
_MAKEEXT.PRG
< prev
next >
Wrap
Text File
|
1993-05-04
|
5KB
|
149 lines
FUNCTION _MakeExte
PARAMETER pc_fname
*--------------------------------------------------------------------
* NAME
* _MAKEEXTE - Creates a dBASE IV structure extended
* file.
*
* SYNOPSIS
* _MAKEEXTE( pc_fname )
*
* DESCRIPTION
* The _MAKEEXTE() function creates an empty dBASE IV
* structure extended file. It uses low-level file
* I/O functions to write the structure directly to
* disk. This file can then be used to create
* other database files.
*
* _MAKEEXTE() will return .T. if the filename was
* created, otherwise .F. If no file extension is
* specified, ".DBF" is assumed.
*
* Be warned that if a file with the same name
* already exists, it will be automatically
* overwritten.
*
* PARAMETER
* pc_fname - the name of the new structure extended
* file to create.
*
* EXAMPLE
*
* * Create a new .DBF with a single field:
* IF _MAKEEXTE( "custtemp" )
* USE custtemp
* APPEND BLANK
* REPLACE field_name WITH "LAST_NAME",;
* field_type WITH "C",;
* field_len WITH 30,;
* field_idx WITH "Y"
* CREATE newdbf FROM custtemp
* ELSE
* ? "Error: Custtemp.dbf not created"
* ENDIF
*
* DEPENDENCIES
* _MAKEEXTE() uses the _FWRITE0 function.
*
* LIMITATIONS
* _MAKEEXTE() expects that TALK is OFF
*
* SEE ALSO:
* COPY STRUCTURE EXTENDED
*
*--------------------------------------------------------------------
PRIVATE lc_newdbf, lh_newdbf, ll_result, ln_bytes
ll_result = .F.
lc_newdbf = LTRIM( RTRIM( pc_fname ) )
IF TYPE('lc_newdbf') = "C" .AND. ( .NOT. ISBLANK( lc_newdbf ) )
lc_newdbf = IIF( .NOT. "." $ lc_newdbf, lc_newdbf, ;
SUBSTR(lc_newdbf, 1, AT(".", lc_newdbf) - 1)) + ".DBF"
lh_newdbf = 0
IF DISKSPACE() < 5000
DEACTIVATE WINDOW _plswait && Deactivate _PlsWait window
DO _Err_Box WITH [Insufficient disk space]
IF LASTKEY() = 28
DO _Helpsys WITH "_FXZERR", "NODISK"
ENDIF
ELSE
lh_newdbf = FCREATE( lc_newdbf, "rw" )
ENDIF
IF lh_newdbf > 0
*-- .dbf with no memos
ln_bytes = FWRITE( lh_newdbf, CHR(3) )
*-- date of last update
ln_bytes = FWRITE( lh_newdbf, ;
CHR( YEAR( DATE() ) - 1900 ) + CHR( MONTH( DATE() ) )+;
CHR( DAY( DATE() ) ) )
*-- No records yet
ln_bytes = _FWRITE0( lh_newdbf, 4 )
*-- Number of bytes in header.
ln_bytes = FWRITE( lh_newdbf, CHR(193) )
ln_bytes = FWRITE( lh_newdbf, CHR(0) )
*-- Number off bytes in each records
ln_bytes = FWRITE( lh_newdbf, CHR(19) )
ln_bytes = FWRITE( lh_newdbf, CHR(0) )
*-- Fill other dbf header stuff
ln_bytes = _FWRITE0( lh_newdbf, 20 )
*-- Write out the extended structure.
ln_bytes = FWRITE( lh_newdbf, "FIELD_NAME" )
ln_bytes = FWRITE( lh_newdbf, CHR(0) )
ln_bytes = FWRITE( lh_newdbf, "C" )
ln_bytes = _FWRITE0( lh_newdbf, 4 )
ln_bytes = FWRITE( lh_newdbf, CHR(10) )
ln_bytes = _FWRITE0( lh_newdbf, 15 )
ln_bytes = FWRITE( lh_newdbf, "FIELD_TYPE" )
ln_bytes = FWRITE( lh_newdbf, CHR(0) )
ln_bytes = FWRITE( lh_newdbf, "C" )
ln_bytes = _FWRITE0( lh_newdbf, 4 )
ln_bytes = FWRITE( lh_newdbf, CHR(1) )
ln_bytes = _FWRITE0( lh_newdbf, 15 )
ln_bytes = FWRITE( lh_newdbf, "FIELD_LEN" )
ln_bytes = _FWRITE0( lh_newdbf, 2 )
ln_bytes = FWRITE( lh_newdbf, "N" )
ln_bytes = _FWRITE0( lh_newdbf, 4 )
ln_bytes = FWRITE( lh_newdbf, CHR(3) )
ln_bytes = _FWRITE0( lh_newdbf, 15 )
ln_bytes = FWRITE( lh_newdbf, "FIELD_DEC" )
ln_bytes = _FWRITE0( lh_newdbf, 2 )
ln_bytes = FWRITE( lh_newdbf, "N" )
ln_bytes = _FWRITE0( lh_newdbf, 4 )
ln_bytes = FWRITE( lh_newdbf, CHR(3) )
ln_bytes = _FWRITE0( lh_newdbf, 15 )
ln_bytes = FWRITE( lh_newdbf, "FIELD_IDX" )
ln_bytes = _FWRITE0( lh_newdbf, 2 )
ln_bytes = FWRITE( lh_newdbf, "C" )
ln_bytes = _FWRITE0( lh_newdbf, 4 )
ln_bytes = FWRITE( lh_newdbf, CHR(1) )
ln_bytes = _FWRITE0( lh_newdbf, 15 )
*-- Write the field (header) terminator
ln_bytes = FWRITE( lh_newdbf, CHR(13) )
IF FCLOSE( lh_newdbf )
ll_result = .T.
ENDIF
ENDIF && Could not create DBF skeleton
ENDIF && Parameters not correct
RETURN( ll_result )
*-- EOF: _MakeExte( pc_fname )